<div class="panel-admin">
	<div class="row-fluid">
		<div class="span5">			
			<h1>Articles</h1>
			<p>รายการร้านค้าทั้งหมด</p>
		</div>
		<div class="span7 text-right">
			<form class="form-search">
			  <input type="text" class="input-medium search-query">
			  <button type="submit" class="btn">Search</button>
			</form>
		</div>
	</div>
	<div class="panel-admin-inner">
		<div class="navbar">
			<div class="navbar-inner">
				<div class="text-right">
					<a class="btn btn-primary" href="<?php print base_url(); ?>admin/article/add">เพิ่มใหม่</a>
					<button class="btn btn-danger">ลบที่เลือก</button>
				</div>
			</div>
		</div> 
		<div class="panel-message"></div>		
		<table class="table">
			<thead>		
				<th style="width:5%;"></th>		
				<th style="width:45%;"></th>				
				<th style="width:20%;"></th>
				<th style="width:10%;"></th>
				<th style="width:10%;"></th>
				<th style="width:10%"></th>
			</thead>
			<tbody>
				<?php for ($i=0; $i<count($data); $i++): ?>
				<tr>			
					<td><input type="checkbox" /></td>		
					<td><?php print $data[$i]['ART_TITLE']; ?></td>
					<td><?php print $data[$i]['ART_CAT_NAME']; ?></td>					
					<td>
						<?php if ($data[$i]['ART_FEATURE']): ?>
							<button class="btn btn-mini btn-favorite active" value="<?php print $data[$i]['ART_CODE']; ?>"><i class="icon-star"></i></button>
						<?php else: ?>
							<button class="btn btn-mini btn-favorite" value="<?php print $data[$i]['ART_CODE']; ?>"><i class="icon-star"></i></button>
						<?php endif; ?>							
					</td>
					<td>
						<div class="switch switch-mini switch-state" data-on="success" data-off="danger">
							<?php if ($data[$i]['ART_PUBLISHED']): ?>
						    	<input type="checkbox" checked />
						    <?php else: ?>
						    	<input type="checkbox"  />
						    <?php endif; ?>
						</div>
					</td>						
					<td>
						<div class="btn-group">
							<a class="btn btn-mini btn-primary dropdown-toggle" data-toggle="dropdown" href="#">
								Action <span class="caret"></span>
							</a>
							<ul class="dropdown-menu" style="left:-100px;">
							    <li><a href="<?php print base_url(); ?>admin/article/view/<?php print $data[$i]['ART_CODE']; ?>"><i class="icon-list-alt"></i> รายละเอียด</a></li>
							    <li><a href="#" class="remove-item"><input type="hidden" value="<?php print $data[$i]['ART_CODE']; ?>" /><i class="icon-remove"></i> ลบ</a></li>
							</ul>
						</div>						
					</td>
				</tr>
				<?php endfor; ?>
			</tbody>			
		</table>	
	</div>
	<div class="pagination">
		<?php if ($max_count > 0){?>	
			<ul>
			    <li><a href="<?php print base_url() . 'admin/article/list?p=' . 1; ?>">First</a></li>    
			    <?php for ($i=0; $i<$max_count; $i++) {?>
			      	<li><a href="<?php print base_url() . 'admin/article/list?p=' . ($i+1); ?>"><?php print $i+1; ?></a></li>
			    <?php }?>
			    <li><a href="<?php print base_url() . 'admin/article/list?p=' . $max_count; ?>">Last</a></li>
			</ul>
		<?php } ?>
	</div>
</div>
<script type="text/javascript">
	$(function(){
		$('.remove-item').click(function(){
			var arr = new Array();
			arr['a'] = $(this).find('input[type=hidden]').val();
			create_confirm_model('<?php print base_url() .'admin/article/list/ajax_remove'; ?>', arr,  'ยืนยันการลบช้อมูล', true);			
		});
		$('.switch-state').on('switch-change', function (e, data){
			$.post('<?php print base_url() .'admin/article/list/ajax_change_state'; ?>', { a : $(this).parents('tr').find('input[type=hidden]').val(),  s : data.value }, function(output){
				switch (output.result){
				    case -2: {
				    	alert(output.message);	    	
				    	window.location.href = output.redirect_url;
				    }
				    break;
			    }	
			}, 'json');
		});
		$('.btn-favorite').click(function(){
			var state;
			
			if ($(this).hasClass('active')){
				$(this).removeClass('active');
				state = 0;
			}else{
				$(this).addClass('active');
				state = 1;
			}
			
			$.post('<?php print base_url() . 'admin/article/list/ajax_set_feature'; ?>', { a : $(this).val(), s : state }, function(output){
				switch (output.result){
				    case -2: {
				    	alert(output.message);				    	
				    	window.location.href = output.redirect_url;
				    }
				    break;
			    }
			}, 'json');
		});
	})
</script>
